package labox.innovation.gameserver.model.actor;

import java.util.Collection;

import labox.innovation.gameserver.model.L2ItemInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.network.serverpackets.AbstractNpcInfo;
import labox.innovation.gameserver.taskmanager.DecayTaskManager;
import labox.innovation.gameserver.templates.chars.CharTemplate;
import labox.innovation.gameserver.templates.chars.NpcTemplate;
import labox.innovation.gameserver.templates.item.L2Weapon;

public abstract class L2Decoy extends L2Character {
	
	private FuzePcInstance _owner;

	public L2Decoy(int objectId, CharTemplate template, FuzePcInstance owner) {
		super(objectId, template);
		_owner = owner;
		setXYInvisible(owner.getX(), owner.getY());
		setIsInvul(false);
	}

	@Override
	public void onSpawn() {
		super.onSpawn();
//		getOwner().sendPacket(new AbstractNpcInfo.DecoyInfo(this));
	}

	@Override
	public void onAction(FuzePcInstance player) {
		player.setTarget(this);
	}

	@Override
	public void updateAbnormalEffect() {
		Collection<FuzePcInstance> plrs = getKnownList().getKnownPlayers().values();
//		for (FuzePcInstance player : plrs)
//			player.sendPacket(new AbstractNpcInfo.DecoyInfo(this));
	}

	public void stopDecay() {
		DecayTaskManager.getInstance().cancelDecayTask(this);
	}

	@Override
	public void onDecay() {
		deleteMe(_owner);
	}

	@Override
	public boolean isAutoAttackable(L2Character attacker) {
		return _owner.isAutoAttackable(attacker);
	}

	@Override
	public L2ItemInstance getActiveWeaponInstance() {
		return null;
	}

	@Override
	public L2Weapon getActiveWeaponItem() {
		return null;
	}

	@Override
	public L2ItemInstance getSecondaryWeaponInstance() {
		return null;
	}

	@Override
	public L2Weapon getSecondaryWeaponItem() {
		return null;
	}

	public final int getNpcId() {
		return getTemplate()._id;
	}

	@Override
	public int getLevel() {
		return getTemplate().level;
	}

	public void deleteMe(FuzePcInstance owner) {
		decayMe();
		getKnownList().removeAllKnownRegion();
		owner.setDecoy(null);
	}

	public synchronized void unSummon(FuzePcInstance owner) {
		if (isVisible() && !isDead()) {
			if (getScene() != null)
				getScene().removeFromZones(this);
			owner.setDecoy(null);
			decayMe();
			getKnownList().removeAllKnownRegion();
		}
	}

	public final FuzePcInstance getOwner() {
		return _owner;
	}

	@Override
	public FuzePcInstance getActingPlayer() {
		return _owner;
	}

	@Override
	public NpcTemplate getTemplate() {
		return (NpcTemplate) super.getTemplate();
	}

	@Override
	public void sendInfo(FuzePcInstance activeChar) {
//		activeChar.sendPacket(new AbstractNpcInfo.DecoyInfo(this));
	}
}
